using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Mehat.San.SanFS
{
	public delegate void VMountNotifierHandler(IVirtualMount VMount);
	
	public class VirtualMountManager
	{
		private static Dictionary<VirtualMountType, IVirtualMount>	mObjectRegistry = new Dictionary<VirtualMountType,IVirtualMount>();
		private static Dictionary<string, IVirtualMount>			mVMounts = new Dictionary<string,IVirtualMount>();
		
		public static event VMountNotifierHandler					Added = null;
		public static event VMountNotifierHandler					Removed = null;

		public static void Initialize()
		{
			mObjectRegistry.Add(VirtualMountType.Path, new PathVirtualMount());
			//mObjectRegistry.Add(VirtualMountType.Device, new DeviceVirtualMount());
			mObjectRegistry.Add(VirtualMountType.MediaChanger, new MediaChangerVirtualMount());
		}

		public static IVirtualMount Create(XmlNode ConfigNode)
		{
			XmlNode				typeNode = ConfigNode.Attributes.GetNamedItem("Type");
			VirtualMountType	type = (VirtualMountType) Enum.Parse(typeof(VirtualMountType), typeNode.Value, true);
			IVirtualMount		newVMount = null;
			
			Console.WriteLine("VirtualMountManager.Create(): Creating new VMount type '{0}'", type);
			newVMount = mObjectRegistry[type].CreateInstance(ConfigNode);
			mVMounts.Add(ConfigNode.Attributes.GetNamedItem("Name").Value, newVMount);
			
			if (Added != null)
				Added(newVMount);		 
			return newVMount;
		}
		
		public static void Destroy(IVirtualMount VirtualMount)
		{
			if (Removed != null)
				Removed(VirtualMount);
			throw new NotImplementedException();
		}

		public static int Count
		{
			get { return mVMounts.Count; }
		}
	}  // END CLASS
}  // END NAMESPACE
